Skip to main content

Chapter 34 - Terraform Cloud - Private Module Registry

Hosting your modules in a private registry

image.png

Demo

  1. Create a new private repository in GitHub for our Static Website demo
  2. Copy the files from Git 55 Modules manifest folder to your repo and commit and push.
  3. Create a new release (v1.0.0)

Terraform Cloud Private Module


  1. Log into TF Cloud and publish a new module
  2. Select the repo and publish
  3. It should match the type of repo you have in GitHub.

image.png

Github Custom


Add VCS Provider using OAuth. V173 for reference.

  1. Go to TF Cloud -> Organization -> Registry tab
  2. Click on publish private module
  3. You'll be prompted to create a new application on GitHub. Click that link and register the application
    image.png image.png
  4. Grab the client ID and generate a secret and enter it in the screen as shown above.

You will be prompted to confirm that the app can have the access:
image.png

Publish module via Github Custom:

image.png

Create TF Configs, use source as Private Module


static-website.tf:

# Call our Custom Terraform Module which we built earlier
module "staticwebsiteprivate" {
source = "app.terraform.io/dupo-internal/staticwebsiteprivate/azurerm"
version = "1.0.0"

# Resource Group
location = "eastus"
resource_group_name = "myrg1"

# Storage Account
storage_account_name = "staticwebsite"
storage_account_tier = "Standard"
storage_account_replication_type = "LRS"
storage_account_kind = "StorageV2"
static_website_index_document = "index.html"
static_website_error_404_document = "error.html"
}

NOTE: If running on the CLI, you will need to authenticate into the private repo:

credentials "app.terraform.io" {
# valid user API token
token = "xxxxxx.atlasv1.zzzzzzzzzzzzz"
}

You will need to create a token on Terraform Cloud or log in to Terraform Cloud on the CLI.

You will get an Error accessing terraform registry message without logging in to a private registry